<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 2015/1/28
 * Use : ...
 * File: UrlRule.php
 */

namespace ulue\core\router;



class RuleParser
{
    // 规则列表 只能匹配一条规则：匹配到一条后，就不在往后检查
    protected $rules = [];

    private $router;

    // 匹配到的规则
    protected $matchRule = null;

    public function __construct($rules, Router $router)
    {
        $this->rules  = $rules;
        $this->router = $router;
    }

    /**
     * @param  string $path
     * @return string
     */
    public function matchPath($path)
    {
        return false;
    }

    /**
     * [ruleKeywords 路由规则关键字
     * @example <year>/<month>/<day> 相当于  <year:\d{1,4}>/<month:\d{1,2}>/<day:\d{1,2}>
     * @param $config
     * @return array [type]        [description]
     */
    public function ruleKeywords($config)
    {
        $default = [
            // '<@datatime>'           => '<@call:date|@param:Y-m-d>',
            // '<@year/month>'         => '<@call:date|@param:Y/m/1>',
            // '<@year/month/day>'     => '<@call:date|@param:Y/m/d>',

            '<@year>'               => '<year:[1-9]\d{3}>',
            '<@number>'             => '<number:-?\d+>',
        ];

        return empty($config) ? $default : array_merge( $default ,(array) $config);
    }

} // end class UrlRule